package com.mazaiting.manager.listeners;

import com.mazaiting.manager.listeners.event.RuleRelationEvent;
import com.mazaiting.manager.service.ISysPermissionService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 角色与权限/URL事件监听
 *
 * @author mazaiting
 * @create_time 2022/9/8 22:52
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class RuleRelationListener implements ApplicationListener<RuleRelationEvent> {

    private final ISysPermissionService sysPermissionService;

    @Async
    @Override
    public void onApplicationEvent(@NonNull RuleRelationEvent event) {
        log.info("=======初始化权限信息开始=======");
        boolean result = sysPermissionService.reloadPermRolesRules();
        log.info("权限角色规则信息加载: " + (result ? "success" : "fail"));
        log.info("=======初始化权限信息结束=======");
    }
}
